package com.example.demo.config;

import com.example.demo.common.TokenExpiredException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;


@RestControllerAdvice
public class ExceptionAdvice {

    /**
     * 全局异常捕捉处理
     * @param ex
     * @return
     */
    @ExceptionHandler(value = Exception.class)
    public String errorHandler(Exception ex) {
        if (ex instanceof TokenExpiredException){
           return ex.getMessage();
        } else if (ex instanceof NullPointerException){
            return ex.getMessage();
        } else if (ex instanceof IndexOutOfBoundsException) {
            return ex.getMessage();
        }
        ex.printStackTrace();
        return ex.getMessage();
    }
}
